<div class="properties-rows">
	<div class="row"><?php foreach ($listings as $listing) { ?> 
		<?php 
		//get media for listing
		$media = $this->mdl_listingmapmodel->get_media($listing['Listing_ID'], "Cover", 1);
		
		?>
		<div class="property span9">
			<div class="row">
			<div class="image span3">
				<div class="content">
					<?php if(isset($media->FileName) && isset($media->FileExtension)) { ?>
					<a href="<?php base_url(); ?>detail/<?php echo $listing['Link']; ?>"><img src="<?php echo $this->config->item('HTTP_LISTING_MEDIA_IMAGE') . $listing['Listing_ID'] . '/' . $media->FileName . '-270x200' . $media->FileExtension; ?>" alt=""></a> 
					<?php } else { ?> 
					<img src="<?php echo $this->config->item('HTTP_IMAGE'); ?>tmp/no-image.png" alt=""> 
					<?php } ?>
				</div>
				<div class="price price2">
					<?php if($listing['Price_Min'] > 0) { ?> 
						<?php echo $listing['PriceUnit'] . " " . number_format(($listing['Price_Min']), 0, '.', ','); ?>
					<?php } else { ?> 
						<?php echo "Price On Application"; ?> 
					<?php } ?>
				</div>
				<!-- /.price -->
				<?php if($listing['Price_Min'] > 0) { ?>
				<div class="row-fluid">
					<?php
						if (isset($listing['CountryFID']) && $listing['CountryFID'] == COUNTRY_ID) {
							$currency_rate = $this->helpermodel->getRateByUnitCurrency($listing['PriceUnit']);
							$price_usd = $listing['Price_Min'] / $currency_rate;
							$price_usd_formatted = USD_UNIT . " " . number_format(($listing['Price_Min'] / $currency_rate), 0, '.', ',');
						} else {
							$currency_rate = $this->helpermodel->getRateByUnitCurrency($listing['PriceUnit']);
							$price_usd = $listing['Price_Min'] / $currency_rate;
							$price_usd_formatted = USD_UNIT . " " . number_format(($listing['Price_Min'] / $currency_rate), 0, '.', ',');
						}
					?>
					<div class="pull-left span8 spanusd">
						Estimated <?php echo $price_usd_formatted; ?>
					</div>
					<div class="pull-right span4">
						<select name="curencyid" class="curencyid_ajax span12">
							<option value="AUD">AUD</option>
							<option value="CNY">CNY</option>
							<option value="EUR">EUR</option>
							<option value="GBP">GBP</option>
							<option value="HKD">HKD</option>
							<option value="IDR">IDR</option>
							<option value="INR">INR</option>
							<option value="JPY">JPY</option>
							<option value="NZD">NZD</option>
							<option value="SGD">SGD</option>
							<option value="THB">THB</option>
							<option value="USD" selected="selected">USD</option>
							<option value="VND">VND</option>
						</select>
					</div>
					<span class="price asking_price_local_int" style="visibility: hidden;with:0px;height: 0px;position: absolute">
						<?php echo $listing['PriceUnit'] . " " . number_format(($listing['Price_Min']), 0, '.', ','); ?>
                    </span>
					<span class="price_usd" style="visibility: hidden;with:0px;height: 0px;position: absolute"><?php echo trim($price_usd); ?>
                   	</span>
                   	<span class="unit_price" style="visibility: hidden;with:0px;height: 0px;position: absolute"><?php echo $listing['PriceUnit']; ?></span>
				</div>
				<!-- /.content -->
				<?php } ?>
			</div>
			<!-- /.image -->
			
			<div class="body span6">
				<div class="title-price row">
					<div class="title span5">
						<h2><a href="<?php echo base_url(); ?>detail/<?php echo $listing['Link']; ?>"><?php echo strtoupper($listing['ProjectName']); ?></a></h2>
					</div>
					<!-- /.title -->
					<div class="social">
						<div class="review">
							<div class="share"><!-- AddThis Button BEGIN -->
								<div class="addthis_default_style">
									<a class="addthis_button_facebook"
								        addthis:url="<?php echo base_url(); ?>detail.html?id=<?php echo $listing['Listing_ID']; ?>"
								        addthis:title="<?php echo $listing['ProjectName']; ?>"
								        addthis:description="<?php echo $listing['ProjectName']; ?>"></a> 
									<a class="addthis_button_twitter"
										addthis:url="<?php echo base_url(); ?>detail.html?id=<?php echo $listing['Listing_ID']; ?>"
								        addthis:title="<?php echo $listing['ProjectName']; ?>"
								        addthis:description="<?php echo $listing['ProjectName']; ?>">
									</a>
									<a class="addthis_button_email"
										addthis:url="<?php echo base_url(); ?>detail.html?id=<?php echo $listing['Listing_ID']; ?>"
								        addthis:title="<?php echo $listing['ProjectName']; ?>"
								        addthis:description="<?php echo $listing['ProjectName']; ?>">
									</a>
								</div>
								<script type="text/javascript"
									src="//s7.addthis.com/js/250/addthis_widget.js">
								</script> <!-- AddThis Button END -->
							</div>
						</div>
					</div>
				</div>
				<!-- /.title -->
				
				<div class="w-box-content-3 cnt_a property-detail">
					<div class="row-fluid">
						 <div class="span4">
						 	<ul class="span12">
						 		<?php if(isset($localorInt) && $localorInt == 1) { ?>
						 		<li class="">
									<?php echo $listing['Country']; ?>
								</li>
								<?php } ?>
								<li class="">
									<?php echo $listing['PropertyType']; ?>
								</li>
								<li class="">
									<?php if($listing['Price_Min'] > 0) { ?>
										 <?php if($listing['Size_Min'] > 0) { ?>
											<?php echo $listing['PriceUnit'] . " " . number_format(($listing['Price_Min']/$listing['Size_Min']), 2, '.', ','); ?> PSF
										<?php } else { ?>
											<?php echo "Price On Application"; ?>
										<?php } ?>
									<?php } else { ?> 
										<?php echo "Price On Application"; ?> 
									<?php } ?>
								</li>
							</ul>
						 </div>
						 <div class="span4">
						 	<ul class="span12">
								<li class="">
									<?php echo number_format($listing['Size_Min']) . ' ' . $listing['SizeUnit']; ?> (built-in)
								</li>
								<li class="">
									<?php echo $listing['Tenure']; ?>
								</li>
							</ul>
						 </div>
						 <div class="span4">
						 	<div class="row-fluid">
						 		<?php if(isset($listing['Latitude']) && isset($listing['Longitude'])) { ?>
						 		<div class="span4 pull-left">
                             		<a class="opendetail gmap sepH_b" href="<?php echo "detail/map_pop.html?id=". $listing['Listing_ID']; ?>"><div class="gmap sepH_b"></div></a>
						 		</div>
						 		<?php } ?>
						 		<div class="span8">
						 			<ul class="span12">
										<div class="control-group">
											<div class="controls">
												<div class="bedrooms bedrooms_result sepH_b">
													<div class="content"><?php echo $listing['Bedroom']; ?></div>
												</div>
												<div class="bathrooms bathrooms_result sepH_b">
													<div class="content"><?php echo $listing['Bathroom']; ?></div>
												</div>
											</div>
										</div>
									</ul>
						 		</div>
						 	</div>
						 </div>
					</div>		
				</div>
				<div class="w-box-content-4">
					<div class="pull-left">
						<div class="area sepH_b">
							<p><span>
								<strong>(Guide Price)</strong></span> <br/>
								<span>Listed on <?php echo date('F j, Y', strtotime($listing['ListedOnUtc'])); ?></span>
							</p>
						</div>
					<!-- /.area -->
					</div>
					<div class="clearfix"></div>
					<div id="contact-this-agent" class="pull-right morelinks">
						<?php 
						//get Agent By ID
						$data['agentInfo'] = array();
						//$result = $this->mdl_member->getAgentInfo($this->input->get('id'), $this->config->item('config_language_id'),$this->config->item('market'));
						$user_id = $this->mdl_listingmapmodel->getUser($listing['Listing_ID']);
						$result = $this->mdl_listingmapmodel->getAgentInfo($user_id, $this->config->item('config_language_id'),$this->config->item('market'));
						
						$agentPhoto =  "";
						
						if($result) {
							$mobile = MOBILE_EXT . $result->Mobile;
							$data['agentInfo'] = array(
								'Agent_ID'		=> $user_id,
								'Name'			=> $result->BusinessName,
								'Mobile'		=> $mobile,
								'Email'			=> $result->Email,
								'AgentPhoto'	=> $agentPhoto,
								'RegistrationNo'=> $result->CEA_RegistrationNo,
								'AgentLicenceNo'=> $result->CEA_LicenceNo,
								'LicenceNo'		=> $result->LicenceNo
							);
						}
						?>
						<?php if($result) { ?>
						<button class="btn btn-primary find_an_expert_btn" data-toggle="modal" data-target="#myModal_<?php echo $listing['Listing_ID']; ?>">
						Contact Agent
						</button>
						<div id="myModal_<?php echo $listing['Listing_ID']; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
							<form action="" id="validate_field_contact_agent_detail_listing" class="button-contact-agent-result-listing">
								<input type="hidden" name="agent_email" value="<?php echo $data['agentInfo']['Email']; ?>">
								<input type="hidden" name="agent_id" value="<?php echo $user_id; ?>" class="agent_id">
								<input type="hidden" name="listing_id" value="<?php echo $listing['Listing_ID']; ?>" >
								<input type="hidden" name="listing_name" value="<?php echo $listing['ProjectName']; ?>" >
								<input type="hidden" name="action" value="sendenquiry" />
								<div class="modal-header">
								  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
								  <h3 id="myModalLabel">Contact this Agent</h3>
								  <div class="message_notification"></div>
								</div>
								<div class="modal-body">
									<div class="content">
										<div class="row-fluid">
											<div class="image span4">
												<img src="<?php echo base_url(); ?>detail/getAgentProfilePhoto/<?php echo $user_id;?>" alt="<?php echo $data['agentInfo']['Name']; ?>">
											</div>
											<div class="body span8">
												<h3><?php echo $data['agentInfo']['Name']; ?></h3>
												<p>CEA Registration Number: <?php echo $data['agentInfo']['AgentLicenceNo']; ?></p>
												<h5><a><?php echo $data['agentInfo']['Mobile']; ?></a></h5>
												<h5><a href="mailto:<?php echo $data['agentInfo']['Email']; ?>"><?php echo $data['agentInfo']['Email']; ?></a></h5>
												<?php if($data['agentInfo']['LicenceNo'] == "L3010359I") { ?>
												<p>Jones Lang LaSalle Residential Pte Ltd</p>
												<?php } else { ?>
												<p>Jones Lang LaSalle Property Consultants Pte Ltd</p>
												<?php } ?>
												<p>CEA Licence Number: <?php echo $data['agentInfo']['LicenceNo']; ?></p>
											</div>
										</div>
										<div class="row-fluid">
											<div class="span4">
												<input type="text" name="name" id="name" class="span12 agent_name" maxlength="20" value="Name">
											</div>
											<div class="span4">
												<input type="text" name="phone" id="phone" class="span12 agent_phone" maxlength="20" value="Phone">
											</div>
											<div class="span4">
												<input type="text" name="email" id="email" class="span12 agent_email" value="Email">
											</div>
										</div>
										<div class="row-fluid">
											<textarea class="span12" name="agent_message" id="agent_message" cols="70" rows="3"><?php echo html_entity_decode(sprintf($text_contact_this_agent_to_schedule_a_meeting, $data['agentInfo']['Name'], strtoupper($listing['ProjectName'])) , ENT_QUOTES, 'UTF-8'); ?></textarea>
										</div>
									</div>
								</div>
								<div class="modal-footer">
								  <input type="submit" value="Send" id="" class="btn btn-primary">
								</div>
							</form>
						</div>
						<?php } ?>
						<button class="btn btn-primary view_detail">View Details</button>
                      	<?php if(in_array($listing['Listing_ID'], $shortlist) ) {?>
                      	<button class="btn btn-primary short_list disabled">Shortlisted</button>
                        <?php } else { ?>
						<button class="btn btn-primary short_list">Shortlist</button>
						<?php } ?>
						<input type="hidden" value="<?php echo $listing['Link']; ?>" name="morelinks" id="morelinks">
					</div>
					<div class="clearfix"></div>
				</div>
			</div>
			<!-- /.body --></div>
		<!-- /.property -->
		</div>
		<!-- /.row --> <?php } ?>
	</div>
<!-- /.row -->
</div>
<!-- /.properties-rows -->
